package com.ruoyi.ysg.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.ysg.domain.YsgTeacherUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ysg.domain.YsgTeacher;
import com.ruoyi.ysg.service.IYsgTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师管理Controller
 *
 * @author xsz
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/ysg/teacherManage")
public class YsgTeacherController extends BaseController
{
    @Autowired
    private IYsgTeacherService ysgTeacherService;

    /**
     * 查询教师管理列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(YsgTeacher ysgTeacher)
    {
        startPage();
        List<YsgTeacher> list = ysgTeacherService.selectYsgTeacherList(ysgTeacher);
        return getDataTable(list);
    }

    /**
     * 查询学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:list')")
    @GetMapping("/unAssociatedUserList")
    public TableDataInfo unAssociatedUserList(SysUser user)
    {
        startPage();
        List<SysUser> list = ysgTeacherService.unAssociatedUserList(user);
        return getDataTable(list);
    }

    /**
     * 查询学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:list')")
    @GetMapping("/getAssociatedUser")
    public TableDataInfo getAssociatedUser(String teacherId)
    {
        startPage();
        List<SysUser> list = ysgTeacherService.getAssociatedUser(teacherId);
        return getDataTable(list);
    }

    /**
     * 导出教师管理列表
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:export')")
    @Log(title = "教师管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YsgTeacher ysgTeacher)
    {
        List<YsgTeacher> list = ysgTeacherService.selectYsgTeacherList(ysgTeacher);
        ExcelUtil<YsgTeacher> util = new ExcelUtil<YsgTeacher>(YsgTeacher.class);
        util.exportExcel(response, list, "教师管理数据");
    }

    /**
     * 获取教师管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ysgTeacherService.selectYsgTeacherById(id));
    }

    /**
     * 新增教师管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:add')")
    @Log(title = "教师管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YsgTeacher ysgTeacher)
    {
        return toAjax(ysgTeacherService.insertYsgTeacher(ysgTeacher));
    }

    /**
     * 新增教师管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:add')")
    @Log(title = "教师绑定用户", businessType = BusinessType.INSERT)
    @PostMapping("/associate")
    public AjaxResult associate(@RequestBody YsgTeacherUser ysgTeacherUser)
    {
        return toAjax(ysgTeacherService.associate(ysgTeacherUser));
    }

    /**
     * 新增教师管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:add')")
    @Log(title = "教师解绑用户", businessType = BusinessType.DELETE)
    @PostMapping("/unAssociate")
    public AjaxResult unAssociate(@RequestBody YsgTeacherUser ysgTeacherUser)
    {
        return toAjax(ysgTeacherService.insertunAssociateYsgTeacher(ysgTeacherUser));
    }

    /**
     * 修改教师管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:edit')")
    @Log(title = "教师管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YsgTeacher ysgTeacher)
    {
        return toAjax(ysgTeacherService.updateYsgTeacher(ysgTeacher));
    }

    /**
     * 删除教师管理
     */
    @PreAuthorize("@ss.hasPermi('ysg:teacherManage:remove')")
    @Log(title = "教师管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ysgTeacherService.deleteYsgTeacherByIds(ids));
    }
}
